<?php
class IndexAction extends Action {
	public function _initialize() {
		header("Content-Type:text/html; charset=utf-8");
	}
	/**
	 * 网站首页
	 * 
	 */
	public function index() {
		$dao = D ( "Archives" );
		$condition = array ();
		$condition ['cid'] = '11';
		$news_list = $dao->where ( $condition )->order('ctime DESC')->limit ( "0,9" )->findAll ();
		$this->assign ( "news_list", $news_list );
		$page = array ();
		$page ['title'] = '广州和政文化传播有限公司 -- 旅游门户开发运营、商业投资、项目合作、品牌推广、营销策划、项目托管';
		$page ['keywords'] ='和政文化传播,和政,商业投资,项目合作,品牌推广,营销策划,项目托管';
		$page ['description'] ='广州和政文化传播有限公司致力于：旅游门户开发运营以及商业投资、项目合作、品牌推广、营销策划、项目托管';
		$this->assign ( "page", $page );
		$this->display ();
	}
	
	/**
	 *网站列表
	 *@date 2011-3-21
	 *@time 下午06:41:27
	 */
	function ls() {
		//网站列表
		$cid = intval ( $_GET ['cid'] );
		$cid = empty ( $cid ) ? '11' : $cid;
		$condition = array ();
		$cat = D ( "Cat" );
		$dao = D ( "Archives" );
		$like_link = $cat->where ( "pid='11'" )->order ( "ctime DESC" )->limit ( "0,6" )->findAll ();
		$this->assign ( "like", $like_link );
		if ($cid == '11') {
			$son = $cid . ',';
			foreach ( $like_link as $l ) {
				$son .= $l ['id'] . ',';
			}
			$son = trim ( $son, ',' );
			$condition ['cid'] = array ('in', $son );
		} else {
			$condition ['cid'] = $cid;
		}
		
		$like_link = $dao->where ( $condition )->order("click DESC")->limit('0,6')->findAll();
		$this->assign ( "arc_like", $like_link );
		import ( '@.ORG.ZQPage' );
		$list = array ();
		$count = $dao->where ( $condition )->count ();
		$Page = new ZQPage ( $count, 10 );
		$show = $Page->show ();
		$this->assign ( 'showpage', $show );
		$list = $dao->where ( $condition )->order('ctime DESC')->page ( $Page->getPage () . ",25" )->findAll ();
		$this->assign ( "list", $list );
		//dump($dao->getLastSql());
		

		$type = $cat->where ( "id='{$cid}'" )->find ();
		$this->assign ( "type", $type );
		
		$info = $cat->where ( "id='{$cid}'" )->find ();
		$this->assign ( "info", $info );
		
		$page = array ();
		$page ['title'] = $info ['type_name'].' -- 广州和政文化传播有限公司 ';
		$page ['keywords'] = $info ['type_name'];
		$page ['description'] = $info ['type_name'];
		$this->assign ( "page", $page );
		$this->display ();
	} //end list
	

	/**
	 *网站文章单页
	 *@date 2011-3-21
	 *@time 下午06:42:47
	 */
	function detail() {
		//网站文章单页
		$id = intval ( $_GET ['id'] );
		if ($id) {
			$dao = D ( "Archives" );
			$info = $dao->where ( "id='$id'" )->find ();
			if ($info) {
				$this->assign ( "info", $info );
				$cat = D ( "Cat" );
				$type = $cat->where ( "id='{$info['cid']}'" )->find ();
				$this->assign ( "type", $type );
				
				$like_link = $dao->where ( "cid='{$info['cid']}'" )->order ( "ctime ASC" )->limit ( "0,6" )->findAll ();
				$this->assign ( "like", $like_link );
				
				
				$page = array ();
				$page ['title'] = $info ['title'].' -- 广州和政文化传播有限公司 ';
				$page ['keywords'] = $info ['title'];
				$page ['description'] = $info ['title'];
				$this->assign ( "page", $page );
			} else {
				$this->error ( "数据读取错误，或信息已经删除。" );
			}
		} else {
			$this->error ( "参数错误" );
		}
		$this->display ();
	} //end detail
	
	/**
	 *网站产品服务单页
	 *@date 2011-3-21
	 *@time 下午06:42:47
	 */
	function pro() {
		//网站文章单页
		$id = intval ( $_GET ['id'] );
		if ($id) {
			$dao = D ( "Archives" );
			$info = $dao->where ( "id='$id'" )->find ();
			if ($info) {
				$this->assign ( "info", $info );
				$cat = D ( "Cat" );
				$type = $cat->where ( "id='{$info['cid']}'" )->find ();
				$this->assign ( "type", $type );
				
				$cat = D ( "Cat" );
				$like_link = $cat->where ( "pid='18'" )->order ( "`order` ASC" )->findAll ();
				$this->assign ( "like", $like_link );
				
				$page = array ();
				$page ['title'] = $info ['title'].' -- 广州和政文化传播有限公司 ';
				$page ['keywords'] = $info ['title'];
				$page ['description'] = $info ['title'];
				$this->assign ( "page", $page );
			} else {
				$this->error ( "数据读取错误，或信息已经删除。" );
			}
		} else {
			$this->error ( "参数错误" );
		}
		$this->display ();
	} //end detail
	
		/**
	 *网站产品服务单页
	 *@date 2011-3-21
	 *@time 下午06:42:47
	 */
	function business() {
		//网站文章单页
		$id = intval ( $_GET ['id'] );
		if ($id) {
			$dao = D ( "Archives" );
			$info = $dao->where ( "id='$id'" )->find ();
			if ($info) {
				$this->assign ( "info", $info );
				$cat = D ( "Cat" );
				$type = $cat->where ( "id='{$info['cid']}'" )->find ();
				$this->assign ( "type", $type );
				
				$cat = D ( "Cat" );
				$like_link = $cat->order ( "`order` ASC" )->findAll ();
				$like_link = list_to_tree ( $like_link, 'id', 'pid', '_son', '12' );
				$this->assign ( "like", $like_link );
				
				$page = array ();
				$page ['title'] = $info ['title'].' -- 广州和政文化传播有限公司 ';
				$page ['keywords'] = $info ['title'];
				$page ['description'] = $info ['title'];
				$this->assign ( "page", $page );
			} else {
				$this->error ( "数据读取错误，或信息已经删除。" );
			}
		} else {
			$this->error ( "参数错误" );
		}
		$this->display ();
	} //end detail
	
	/**
	 *单页
	 *@date 2011-3-21
	 *@time 下午06:43:33
	 */
	function page() {
		//单页
		$fname = $_GET ['fname'];
		if ($fname) {
			$condition = array ();
			$condition ['filename'] = $fname;
		} else {
			$this->assign ( "jumpUrl", __APP__ . '/index.html' );
			$this->error ( "参数错误" );
		}
		$dao = D ( "Archives" );
		$info = array ();
		$info = $dao->where ( $condition )->find ();
		$this->assign ( "info", $info );
		
		$cat = D ( "Cat" );
		$type = $cat->where ( "id='{$info['cid']}'" )->find ();
		$this->assign ( "type", $type );
		
		$like_link = $dao->where ( "cid='{$info['cid']}'" )->order ( "ctime ASC" )->limit ( "0,6" )->findAll ();
		$this->assign ( "like", $like_link );
		
		$page = array ();
		$page ['title'] = $info ['title'].' -- 广州和政文化传播有限公司 ';
		$page ['keywords'] = $info ['title'];
		$page ['description'] = $info ['title'];
		$this->assign ( "page", $page );
		
		$cat = D ( "Cat" );
		$son = $cat->order ( "`order` ASC" )->findAll ();
		$son = list_to_tree ( $son, 'id', 'pid', '_son', '1' );
		$this->assign ( "son", $son );
		
		$this->display ();
	} //end page
	

	/**
	 *产品与服务
	 *@date 2011-3-22
	 *@time 下午02:21:43
	 */
	function product() {
		//产品与服务
		$dao = D ( "Archives" );
		$cid = empty ( $_GET ['cid'] ) ? '9' : intval ( $_GET ['cid'] );
		$this->assign ( "cid", $cid );	
		$cat = D ( "Cat" );
		$like_link = $cat->order ( "`order` ASC" )->findAll ();
		$like_link1 = list_to_tree ( $like_link, 'id', 'pid', '_son', '18' );
		$this->assign ( "like", $like_link1 );
		$like_link3 = list_to_tree ( $like_link, 'id', 'pid', '_son', '9' );
		$this->assign ( "like3", $like_link3 );
		$like_link2 = list_to_tree ( $like_link, 'id', 'pid', '_son', '19' );
		$this->assign ( "like2", $like_link2 );
		
		$condition = array ();
		$condition ['cid'] = $cid;
		import ( '@.ORG.ZQPage' );
		$count = $dao->where ( $condition )->count ();
		$Page = new ZQPage ( $count, 10 );
		$show = $Page->show ();
		$this->assign ( 'showpage', $show );
		$list = array ();
		$p=$Page->getPage();
		$limit=$p==1||empty($p)?'':($p*10).',10';
		
		$list = $dao->where ( $condition )->order ( "ctime DESC" )->limit ($limit)->findAll ();
		$this->assign ( "list", $list );
		//dump($dao->getlastsql());
		
		$condition = array ();
		$condition ['id'] = $cid;
		$info = array ();
		$info = $cat->where ( $condition )->find ();
		$this->assign ( "info", $info );
		
		$page = array ();
		$page ['title'] = $info ['type_name'].' -- 广州和政文化传播有限公司 ';
		$page ['keywords'] = $info ['type_name'];
		$page ['description'] = $info ['type_name'];
		$this->assign ( "page", $page );
		
		$this->display ("product2");
	} //end product
	

		/**
	 *产品与服务
	 *@date 2011-3-22
	 *@time 下午02:21:43
	 */
	function zyyw() {
		//产品与服务
		$dao = D ( "Archives" );
		$cid = empty ( $_GET ['cid'] ) ? '9' : intval ( $_GET ['cid'] );
		$this->assign ( "cid", $cid );
		
		$cat = D ( "Cat" );
		$like_link = $cat->order ( "`order` ASC" )->findAll ();
		$like_link = list_to_tree ( $like_link, 'id', 'pid', '_son', '12' );
		$this->assign ( "like", $like_link );
		
		$condition = array ();
		$condition ['cid'] = $cid;
		import ( '@.ORG.ZQPage' );
		$count = $dao->where ( $condition )->count ();
		$Page = new ZQPage ( $count, 10 );
		$show = $Page->show ();
		$this->assign ( 'showpage', $show );
		$list = array ();
		$p=$Page->getPage();
		$limit=$p==1||empty($p)?'':($p*10).',10';
		$list = $dao->where ( $condition )->order ( "ctime DESC" )->limit ($limit)->findAll ();
		$this->assign ( "list", $list );
		
		$condition = array ();
		$condition ['id'] = $cid;
		$info = array ();
		$info = $cat->where ( $condition )->find ();
		$this->assign ( "info", $info );
		
		$page = array ();
		$page ['title'] = $info ['type_name'].' -- 广州和政文化传播有限公司 ';
		$page ['keywords'] = $info ['type_name'];
		$page ['description'] = $info ['type_name'];
		$this->assign ( "page", $page );
		
		$this->display ();
	} //end product
	
	/**
	 *人才招聘
	 *@date 2011-3-22
	 *@time 下午02:23:45
	 */
	function job() {
		//人才招聘
		$condition = array ();
		
		$condition ['filename'] = 'job';
		$dao = D ( "Archives" );
		$info = array ();
		$info = $dao->where ( $condition )->find ();
		$this->assign ( "info", $info );
		
		$cat = D ( "Cat" );
		$type = $cat->where ( "id='{$info['cid']}'" )->find ();
		$this->assign ( "type", $type );
		
		$like_link = $dao->where ( "cid='{$info['cid']}'" )->order ( "ctime ASC" )->limit ( "0,6" )->findAll ();
		$this->assign ( "like", $like_link );
		
		$page = array ();
		$page ['title'] = $info ['title'].' -- 广州和政文化传播有限公司 ';
		$page ['keywords'] = $info ['title'];
		$page ['description'] = $info ['title'];
		$this->assign ("page", $page );
		$this->display ();
	} //end job
	

	/**
	 *信息反馈
	 *@date 2011-3-24
	 *@time 上午11:28:49
	 */
	function feedback() {
		//信息反馈
		$dao = D ( "Archives" );
		$like_link = $dao->where ( "cid='1'" )->order ( "ctime ASC" )->limit ( "0,6" )->findAll ();
		$this->assign ( "like", $like_link );
		if ($_POST ['title']) {
			$data = array ();
			$vo = array ();
			foreach ( $_POST as $k => $v ) {
				$data [$k] = strip_tags ( $v );
			}
			$fdbk = D ( "Feedback" );
			$vo ['title'] = $data ['title'];
			$vo ['ctime'] = time ();
			$vo ['lmxi'] = $data ['lmxi'];
			$vo ['content'] = $data ['content'];
			$vo ['is_new'] = 1;
			$id = $fdbk->add ( $vo );
			if ($id) {
				$this->success ( "信息发送成功。" );
			} else {
				$this->error ( "信息发送失败。" );
			}
		}
		$page = array ();
		$page ['title'] = '信息反馈 -- 广州和政文化传播有限公司 ';
		$page ['keywords'] ='和政,信息反馈,在线应聘';
		$page ['description'] ='广州和政文化传播有限公司信息反馈系统，在线应聘.';
		$this->assign ( "page", $page );
		$this->display ();
	} //end feedback
	

	/**
	 *下载
	 *@date 2011-3-25
	 *@time 上午10:23:45
	 */
	function download() {
		//下载
		$cid = intval ( $_GET ['cid'] );
		$cid = empty ( $cid ) ? '15' : $cid;
		$condition = array ();
		$cat = D ( "Cat" );
		$like_link = $cat->order ( "`order` ASC" )->findAll ();
		$like_link = list_to_tree ( $like_link, 'id', 'pid', '_son', '15' );
		$this->assign ( "like", $like_link );

		if ($cid == '15') {
			$son = $cid . ',';
			foreach ( $like_link as $l ) {
				$son .= $l ['id'] . ',';
			}
			$son = trim ( $son, ',' );
			$condition ['cid'] = array ('in', $son );
		} else {
			$condition ['cid'] = $cid;
		}
		
		import ( '@.ORG.ZQPage' );
		$dao = D ( "Archives" );
		$list = array ();
		$count = $dao->where ( $condition )->count ();
		$Page = new ZQPage ( $count, 10 );
		$show = $Page->show ();
		$this->assign ( 'showpage', $show );
		$list = $dao->where ( $condition )->page ( $Page->getPage () . ",25" )->findAll ();
		$this->assign ( "list", $list );
		//dump($dao->getLastSql());
		

		$type = $cat->where ( "id='{$cid}'" )->find ();
		$this->assign ( "type", $type );
		
		$info = $cat->where ( "id='{$cid}'" )->find ();
		$this->assign ( "info", $info );
		
		$page = array ();
		$page ['title'] = $info ['type_name'].' -- 广州和政文化传播有限公司 ';
		$page ['keywords'] = $info ['type_name'];
		$page ['description'] = $info ['type_name'];
		$this->assign ( "page", $page );
		$this->display ();
	} //end download
	

	/**
	 *下载内容页
	 *@date 2011-3-25
	 *@time 上午10:24:10
	 */
	function down() {
		//下载内容页
		$id = intval ( $_GET ['id'] );
		if ($id) {
			$dao = D ( "Archives" );
			$info = $dao->where ( "id='$id'" )->find ();
			if ($info) {
				$info ['picture'] = explode ( "|", $info ['picture'] );
				$this->assign ( "info", $info );
				$cat = D ( "Cat" );
				$type = $cat->where ( "id='{$info['cid']}'" )->find ();
				$this->assign ( "type", $type );
				
				$like_link = $dao->where ( "cid='{$info['cid']}'" )->order ( "ctime ASC" )->limit ( "0,6" )->findAll ();
				$this->assign ( "like", $like_link );
				
				$page = array ();
				$page ['title'] = $info ['title'].' -- 广州和政文化传播有限公司 ';
				$page ['keywords'] = $info ['title'];
				$page ['description'] = $info ['title'];
				$this->assign ( "page", $page );
			} else {
				$this->error ( "数据读取错误，或信息已经删除。" );
			}
		} else {
			$this->error ( "参数错误" );
		}
		$this->display ();
	} //end down
	
	//登录操作
	public function login() {
		$page = array ();
		$page ['title'] = '用户登录 -- 广州和政文化传播有限公司 ';
		$page ['keywords'] ='';
		$page ['description'] ='';
		$this->assign ( "page", $page );
		$this->display ();
	}
	//验证登录操作
	public function checklogin() {
		//dump(md5('hezheng!#%'));
		if (empty ( $_POST ['username'] )) {
			$this->error ( '帐号错误！' );
		} elseif (empty ( $_POST ['passwd'] )) {
			$this->error ( '密码必须！' );
		}
		$map ['username'] = $_POST ['username'];
		/*import ( '@.ORG.Right' );
		$authInfo = Right::authCheck ( $map );*/
		$dao=M("User");
		$authInfo=$dao->where($map)->find();
		if (false === $authInfo) {
			$this->error ( '帐号不存在或已禁用！' );
		} else {
			if ($authInfo ['passwd'] != md5 ( $_POST ['passwd'] )) {
				$this->error ( '密码错误！' );
			}
			$_SESSION [C ( 'USER_AUTH_KEY' )] = $authInfo ['id'];
			//如果为管理员
			if ($authInfo ['account'] == 'admin') {
				$_SESSION [C ( 'ADMIN_AUTH_KEY' )] = true;
			}
			//Right::saveRight ();
			$_SESSION['admin']="hezheng!#%";
			$this->redirect ( 'User/cat', '', 3, '登录成功！页面跳转中~~' );
		}
	}
	public function logout() {
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			UNSET ( $_SESSION [C ( 'USER_AUTH_KEY' )] );
			UNSET ( $_SESSION['admin']);
			session_destroy ();
			$this->redirect ( 'Index/login' );
		}
	}
}
?>